//package com.mccken.demo.filter;
//
//import java.io.IOException;
//
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.FilterConfig;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.annotation.WebInitParam;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
//import lombok.extern.slf4j.Slf4j;
//
///**
// * @program: mccken-collect
// * @description:
// * @author: mccken
// * @create: 2022-10-30 16:55
// **/
//@Slf4j
//@WebFilter(urlPatterns = "/*", 
//		filterName = "LoginFilter", 
//		initParams = {
//		        @WebInitParam(name = "includeUrls", value = "/login")
//})
//public class LoginFilter implements Filter {
//	
//	// 不需要登录就可以访问的路径（比如注册登录等）
//	private String includeUrls;
//	
//	@Override
//	public void init(FilterConfig filterConfig) throws ServletException {
//		Filter.super.init(filterConfig);
//		this.includeUrls = filterConfig.getInitParameter("includeUrls");
//	}                                                     
//
//	@Override
//	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//		HttpServletRequest request = (HttpServletRequest) servletRequest;
//		HttpServletResponse response = (HttpServletResponse) servletResponse;
//		HttpSession session = request.getSession();
//		String uri = request.getRequestURI();
//		System.out.println("filter url: " + uri);
//		
//		if (uri.equals(includeUrls)) {
//			filterChain.doFilter(servletRequest, servletResponse);
//		} else {
//			// 需要过滤器
//			if (session != null && session.getAttribute("user") != null) {
//				System.out.println("user: " + session.getAttribute("user"));
//				filterChain.doFilter(servletRequest,servletResponse);
//			} else  {
////				response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
//				response.getWriter().write("未登录");
//				response.sendRedirect("https://www.bilibili.com/");
//			}
//		}
//		
//
//	}
//
//	@Override
//	public void destroy() {
//		System.out.println("destroy");
//		Filter.super.destroy();
//	}
//}
